home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_08 / phil4.c < prev    next >
Text File  |  1991-06-19  |  6KB  |  227 lines

  1.  
  2. Listing 4 - Changes to the function display_image (file display.c)
  3.  
  4.  
  5.  
  6. display_image(file_name, image, il, ie, ll, le,
  7.               image_header, monitor_type, color_transform,
  8.               invert, image_colors, display_colors,
  9.               show_hist)
  10.    char    color_transform[],
  11.            file_name[],
  12.            monitor_type[];
  13.    int     display_colors,
  14.            image_colors,
  15.            invert,
  16.            il,
  17.            ie,
  18.            ll,
  19.            le,
  20.            show_hist;
  21.    short   image[ROWS][COLS];
  22.    struct  tiff_header_struct *image_header;
  23. {
  24.    char  channels[80],
  25.          response[80];
  26.  
  27.    int   a,
  28.          b,
  29.          c,
  30.          channel,
  31.          count,
  32.          display_mode,
  33.          key,
  34.          horizontal,
  35.          max_horizontal,
  36.          max_vertical,
  37.          not_finished,
  38.          r,
  39.          vertical,
  40.          x_offset,
  41.          y_offset;
  42.  
  43.    unsigned int block,
  44.                 color,
  45.                 i,
  46.                 j,
  47.                 x,
  48.                 y;
  49.  
  50.    unsigned long histogram[256], new_hist[256];
  51.  
  52.  
  53.  
  54.      /*************************************************
  55.      *
  56.      *   If you want to display the histogram and do not
  57.      *   want to perform hist equalization, then
  58.      *   zero the histogram for calculations.
  59.      *
  60.      *************************************************/
  61.  
  62.    if(  (show_hist == 1)   &&
  63.         (color_transform[0] != 'H'))
  64.       zero_histogram(histogram);
  65.  
  66.    not_finished = 1;
  67.    while(not_finished){
  68.  
  69.  
  70.       if(display_colors == 16){
  71.          if(monitor_type[0] == 'V'){
  72.             horizontal   = 4;
  73.             vertical     = 6;
  74.             display_mode = _VRES16COLOR; /* MSC 6.0 */
  75.          }  /* ends if V */
  76.          if(monitor_type[0] == 'E'){
  77.             horizontal   = 3;
  78.             vertical     = 6;
  79.             display_mode = _ERESCOLOR; /* MSC 6.0 */
  80.          }  /* ends if E */
  81.  
  82.       }  /* ends if colors == 16 */
  83.  
  84.       else{
  85.          horizontal   = 2;
  86.          vertical     = 2;
  87.          display_mode = _MAXCOLORMODE; /* MSC 6.0 */
  88.       }
  89.  
  90.  
  91.       max_horizontal = (image_header->image_length+50)/100;
  92.       max_vertical   = (image_header->image_width+50)/100;
  93.  
  94.       if(horizontal > max_horizontal) horizontal = max_horizontal;
  95.       if(vertical > max_vertical) vertical = max_vertical;
  96.  
  97.  
  98.  
  99.         /****************************************
  100.         *
  101.         *   If color transform wants histogram
  102.         *   equalization, then read in the
  103.         *   image arrays and calculate the
  104.         *   histogram.   Zero both the histogram
  105.         *   and the new_hist.  You will need the
  106.         *   new_hist if you want to display the
  107.         *   equalized hist.
  108.         *
  109.         *****************************************/
  110.  
  111.       if(color_transform[0] == 'H'){
  112.          count = 1;
  113.          zero_histogram(histogram);
  114.          zero_histogram(new_hist);
  115.          for(a=0; a<vertical; a++){
  116.             for(b=0; b<horizontal; b++){
  117.  
  118.                x = a*100;
  119.                y = b*100;
  120.  
  121.                printf("\nDISPLAY> Calculating histogram");
  122.                printf(" %d of %d",count,vertical*horizontal);
  123.                count++;
  124.                read_tiff_image(file_name, image, il+y,
  125.                             ie+x, ll+y, le+x);
  126.                calculate_histogram(image, histogram);
  127.  
  128.             }  /* ends loop over b */
  129.          }  /* ends loop over a */
  130.       }  /* ends if display_mode == H */
  131.  
  132.  
  133.  
  134.         /* set graphics mode */
  135.  
  136.    _setvideomode(display_mode); /* MSC 6.0 */
  137.    if(display_colors == 16) map_16_shades_of_gray(display_mode);
  138.  
  139.  
  140.  
  141.         /****************************************
  142.         *
  143.         *   Loop over this size and
  144.         *   read and display ROWSxCOLS arrays.
  145.         *
  146.         *   If you want to show the histogram AND
  147.         *   do not want to do hist equalization
  148.         *   then calculate the hist from the 
  149.         *   original image array.
  150.         *
  151.         *   If you want to do hist equalization
  152.         *   then calculate the new_hist AFTER
  153.         *   the image has been equalized by the
  154.         *   the transform_the_colors function.
  155.         *
  156.         *   NOTE: Remember that the function
  157.         *   transform_the_colors changes the
  158.         *   gray shade values in image array.
  159.         *
  160.         *****************************************/
  161.  
  162.       for(a=0; a<vertical; a++){
  163.          for(b=0; b<horizontal; b++){
  164.  
  165.             x = a*100;
  166.             y = b*100;
  167.             read_tiff_image(file_name, image, il+y, 
  168.                             ie+x, ll+y, le+x);
  169.             if(  (show_hist == 1)  &&
  170.                  (color_transform[0] != 'H'))
  171.                calculate_histogram(image, histogram);
  172.  
  173.             transform_the_colors(image, color_transform,
  174.                                  display_colors,
  175.                                  image_colors, histogram,
  176.                                  horizontal, vertical);
  177.  
  178.             if(color_transform[0] == 'H')
  179.                calculate_histogram(image, new_hist);
  180.             display_image_portion(image, x, y, display_colors, 
  181.                                   image_colors, invert);
  182.          }        /* ends loop over b */
  183.       }        /* ends loop over a */
  184.  
  185.  
  186.          /***************************
  187.          *
  188.          *   if show_hist == 1 then
  189.          *   display the histogram
  190.          *   in the lower right hand
  191.          *   corner of screen
  192.          *
  193.          *   If hist equalization was
  194.          *   performed then show the
  195.          *   new_hist.  If it wasn't
  196.          *   done then show the original
  197.          *   histogram.
  198.          *
  199.          ****************************/
  200.  
  201.       if(show_hist == 1){
  202.          if(monitor_type[0] == 'V')
  203.             y_offset = 470;
  204.          if(monitor_type[0] == 'E')
  205.             y_offset = 310;
  206.          x_offset = 380;
  207.          if(color_transform[0] == 'H')
  208.             display_histogram(new_hist, x_offset,
  209.                    y_offset, 10, 15);
  210.          else
  211.             display_histogram(histogram, x_offset,
  212.                    y_offset, 10, 15);
  213.       }
  214.  
  215.       read_string(response);
  216.       printf("\nEnter 0 to quit 1 to do again");
  217.       get_integer(¬_finished);
  218.  
  219.           /* set display back to text mode */
  220.       clear_text_screen();
  221.  
  222.  
  223.    }  /* ends while not_finished  */
  224.  
  225. }
  226.  
  227.